const MyPromise = require('./MyPromise')

// test

// new MyPromise(resolve => resolve(2)).then((value) => { console.log(value); return value; }).then((value) => { console.log(value++); })

// const p1 = new MyPromise((resolve, reject) => {
//   resolve('p1 -> promise')
// })

// const p2 = `p2 is a string`

// const p3 = new MyPromise((resolve, reject) => {
//   resolve('p3 -> promose')
// })

// const p4 = () => { console.log(`p4 is a function`) }

// MyPromise.all([p1, p2, p3, p4]).then(res => {
//   console.log(res)
// })

// let p5 = p1.then((value) => {
//   console.log(value);
//   return p5
// })

// p5.then(() => {}, (err) => { console.log(err.message) })

// let p6 = p3.then(value => {
//   console.log(value)
//   return new MyPromise(resolve => resolve(`this is p3 return value`))
// })

// p6.then(value => {
//   console.log(value)
// }, error => {
//   console.log(error.message)
// })

MyPromise
.race([
  999,
  new MyPromise(resolve => resolve(000)),
  333,
  new MyPromise(resolve => setTimeout(() => { resolve(1) }, 600)),
  new MyPromise(resolve => setTimeout(() => { resolve(2) }, 400)),
  1233
])
.then(res => console.log(res))

MyPromise
.race([
  new MyPromise(resolve => resolve(000)),
  333,
  new MyPromise(resolve => setTimeout(() => { resolve(1) }, 600)),
  new MyPromise(resolve => setTimeout(() => { resolve(2) }, 400)),
  1233
])
.then(res => console.log(res))